package com.xihuanjun.sdk.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xihuanjun.sdk.entity.JSTInout;
import com.xihuanjun.sdk.entity.JSTPageData;
import com.xihuanjun.sdk.enums.JSTMethod;
import com.xihuanjun.sdk.util.JsonUtils;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.*;

/**
 * Copyright (C), 2024-09-06
 * FileName: JSTInOutDao
 * Author:   溪浣君
 * Date:     2024-09-06 16:00
 * Description: 其他出入库操作
 */
@Component
public class JSTInOutDao extends BaseDao{

    /**
     * 查询多条其他出入库单据
     * @param io_id 出库单号，逗号分隔
     * @return
     */
    public List<JSTInout> getListByIds(String io_id) throws IOException {
        String[] split = io_id.split(",");
        Map map=new HashMap();
        map.put("io_ids",split);
        map.put("status","Confirmed");
        return this.jstListQuery(map, JSTMethod.JST_INOUT_QUERY, new TypeReference<List<JSTInout>>() {});
    }

    /**
     * 查询某天所有生效的其他出入库单据
     * @param yyyyMMdd
     * @return
     * @throws IOException
     */
    public List<JSTInout> getListByDay(String yyyyMMdd) throws IOException {
        int pageSize=50;
        List<JSTInout> returnDatas=new ArrayList<>();
        Map map=new HashMap();
        map.put("modified_begin",yyyyMMdd+" 00:00:00");
        map.put("modified_end",yyyyMMdd+" 23:00:00");
        map.put("status","Confirmed");

        int index=1;

        List<JSTInout> listByPage = getListByPage(map,index++, pageSize);
        while(listByPage!=null && listByPage.size()>0){
            returnDatas.addAll(listByPage);
            listByPage = getListByPage(map,index++, pageSize);
        }
        return returnDatas;
    }

    /**
     * 分页查询其他出入库单据
     * @param map 除分页外的查询参数
     * @param pageIndex 页码
     * @param pageSize 每页条数
     * @return
     * @throws IOException
     */
    public List<JSTInout> getListByPage(Map map,int pageIndex,int pageSize) throws IOException {
        map.put("page_size",pageSize);
        map.put("page_index",pageIndex);
        return this.jstListQuery(map,JSTMethod.JST_INOUT_QUERY,new TypeReference<List<JSTInout>>() {});
    }
}
